package util;
import model.User;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;


public class DBUtils {
    private static Properties props;
    static{
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            props=new Properties();
            InputStream inputStream = DBUtils.class.getClassLoader().getResourceAsStream("db.properties");
            props.load(inputStream);
        }catch (IOException e){
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public static Connection getConn() throws SQLException,ClassNotFoundException{

        try{
            return DriverManager.getConnection(
                    props.getProperty("jdbcUrl"),
                    props.getProperty("username"),
                    props.getProperty("password")
            );
        }catch (SQLException e){
            throw new RuntimeException();
        }
    }
}
